/**
 * 2009-11-22 上午11:28:28 
 * esignature
 * com.smc.action.user
 * UserADAction
 */
package com.smc.action.user;

/**
 * @author chenheng
 * @version 0.0.1 管理员表现层控制操作类
 */
public class UserADAction extends AbstractUserAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7115483237413848712L;

	private int items = 0;

	private String role;

	private String resource;

	private String authority;

	public String getAuthority() {
		return authority;
	}

	public void setAuthority(String authority) {
		this.authority = authority;
	}

	public String getResource() {
		return resource;
	}

	public void setResource(String resource) {
		this.resource = resource;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public int getItems() {
		return items;
	}

	public void setItems(int items) {
		this.items = items;
	}

	public String listUnVerifiedUser() {
		String str1 = request.getParameter("pageIndex");
		String str2 = request.getParameter("pageSize");
		int pageIndex = 1;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception e) {
			pageIndex = 1;
		}
		int pageSize = 30;
		try {
			pageSize = Integer.parseInt(str2);
		} catch (Exception ex) {
			pageSize = 30;
		}
		int items = userService.count_AD_US_FE_user(false);
		int pageCount = 1;
		if (items % pageSize == 0) {
			pageCount = items / pageSize;
		} else {
			pageCount = items / pageSize + 1;
		}
		userList = userService.fetch_AD_US_FE_user(false, pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS;
	}

	public String listUser() {
		String str1 = request.getParameter("pageIndex");
		String str2 = request.getParameter("pageSize");
		int pageIndex = 1;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception e) {
			pageIndex = 1;
		}
		int pageSize = 30;
		try {
			pageSize = Integer.parseInt(str2);
		} catch (Exception ex) {
			pageSize = 30;
		}
		items = userService.count_AD_US_FE_user();
		int pageCount = 1;
		if (items % pageSize == 0) {
			pageCount = items / pageSize;
		} else {
			pageCount = items / pageSize + 1;
		}
		userList = userService.fetch_AD_US_FE_user(pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS;
	}

	public String searchUser() {
		String firstName = request.getParameter("firstName");
		String lastName = request.getParameter("lastName");
		String str1 = request.getParameter("pageIndex");
		String str2 = request.getParameter("pageSize");
		int pageIndex = 1;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception e) {
			pageIndex = 1;
		}
		int pageSize = 30;
		try {
			pageSize = Integer.parseInt(str2);
		} catch (Exception ex) {
			pageSize = 30;
		}
		items = userService.count_AD_US_FE_user(firstName, lastName);
		int pageCount = 1;
		if (items % pageSize == 0) {
			pageCount = items / pageSize;
		} else {
			pageCount = items / pageSize + 1;
		}
		userList = userService.fetch_AD_US_FE_user(firstName, lastName,
				pageIndex, pageSize);
		request.setAttribute("firstName", firstName);
		request.setAttribute("lastName", lastName);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS;
	}

	public String getUserByUuid() {
		String uuid = request.getParameter("uuid");
		user = userService.fetch_AD_US_FE_user(uuid);
		return SUCCESS;
	}

	public String verifyUserAuth() {
//		String[] re = resource.split(",");
//		String[] au = authority.split(",");
		int[] authes = null;
		int  mark = Integer.parseInt(role);
		switch (mark) {
		case 1:
			int[] temp1 = {1,65,47};
			authes = temp1 ;
			break ;
		case 2:
			int[] temp2 = {2,9,47};
			authes = temp2 ;
			break ;
		case 4:
			int[] temp3 = {4,25,43};
			authes = temp3 ;
			break ;
		case 8:
			int[] temp4 = {8,40,63};
			authes = temp4 ;
			break ;
		default :
			int[] temp = {0,0,0};
			authes = temp ;
			break ;
		}
//		for (String s1 : re) {
//			authes[1] += Integer.parseInt(s1.trim());
//		}
//		for(String s2:au){
//			authes[2] += Integer.parseInt(s2.trim());
//		}
		userService.save_AD_AU_SA_authentication(user, authes);
		return SUCCESS;
	}
	
	public String listApplyCert() {
		String str1 = request.getParameter("pageIndex");
		String str2 = request.getParameter("pageSize");
		int pageIndex = 1;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception e) {
			pageIndex = 1;
		}
		int pageSize = 30;
		try {
			pageSize = Integer.parseInt(str2);
		} catch (Exception ex) {
			pageSize = 30;
		}
		int pageCount = 1; 
		items = certService.count_AD_IG_FE_certification(false);
		if (items % pageSize == 0) {
			pageCount = items / pageSize;
		} else {
			pageCount = items / pageSize + 1;
		}
		certList = certService.fetch_AD_IG_FE_cerification(false, pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS ;
	}
	public String listAuthCert() {
		String str1 = request.getParameter("pageIndex");
		String str2 = request.getParameter("pageSize");
		int pageIndex = 1;
		try {
			pageIndex = Integer.parseInt(str1);
		} catch (Exception e) {
			pageIndex = 1;
		}
		int pageSize = 30;
		try {
			pageSize = Integer.parseInt(str2);
		} catch (Exception ex) {
			pageSize = 30;
		}
		int pageCount = 1; 
		items = certService.count_AD_IG_FE_certification(true);
		if (items % pageSize == 0) {
			pageCount = items / pageSize;
		} else {
			pageCount = items / pageSize + 1;
		}
		certList = certService.fetch_AD_IG_FE_cerification(true, pageIndex, pageSize);
		request.setAttribute("pageIndex", pageIndex);
		request.setAttribute("pageSize", pageSize);
		request.setAttribute("pageCount", pageCount);
		return SUCCESS ;
	}
	public String deleteCert() {
		String uuid = request.getParameter("uuid");
		certService.remove_AD_IG_RE_certification(uuid);
		return SUCCESS ;
	}
	public String authorityCert() {
		String uuid = request.getParameter("uuid");
		certService.authority_AD_IG_SA_certification(uuid);
		return SUCCESS;
	}
	public String removeUser() {
		String uuid = request.getParameter("uuid");
		userService.remove_AD_US_RE_user(uuid);
		return SUCCESS ;
	}
}
